package com.tianji.chat.controller;


import com.tianji.chat.domain.dto.TaskDTO;
import com.tianji.chat.domain.vo.TaskVO;
import com.tianji.chat.service.ITaskService;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 对话任务表 前端控制器
 * </p>
 *
 * @author pku-hlp
 * @since 2024-01-13
 */
@Api(tags = "对话任务相关接口")
@RestController
@RequestMapping("/task")
@RequiredArgsConstructor
public class TaskController {
    private final ITaskService taskService;

    @ApiOperation("新增任务")
    @PostMapping
    public void saveTask(@Valid @RequestBody TaskDTO taskDTO) {
        taskService.saveTask(taskDTO);
    }


    @ApiOperation("根据任务id修改任务")
    @PutMapping("/{id}")
    public void updateQuestion(
            @ApiParam("要修改的任务的id") @PathVariable("id") Long id,
            @RequestBody TaskDTO taskDTO){
        taskService.updateTask(id, taskDTO);
    }

    @ApiOperation("分页查询当前用户的互动任务")
    @GetMapping("page")
    public PageDTO<TaskVO> queryQuestionPage(PageQuery query){
        return taskService.queryQuestionPage(query);
    }

    @ApiOperation("根据任务id查询互动任务的信息")
    @GetMapping("{id}")
    public TaskVO queryTaskById(@PathVariable("id") Long id){
        return taskService.queryTaskById(id);
    }

    @ApiOperation("根据任务id删除当前用户的任务")
    @DeleteMapping("/{id}")
    public void deleteQuestion(
            @ApiParam(value = "任务id", example = "1") @PathVariable("id") Long id
    ){
        taskService.deleteById(id);
    }

    @ApiOperation("根据点赞数量查询最热门的任务")
    @GetMapping("page/likes")
    public PageDTO<TaskVO> queryMostLikePage(PageQuery query){
        return taskService.queryMostLikePage(query);
    }

}
